/**
 * @PurchaseAction.as
 * @Author - Devendra Kumar Singhal
 * @Version - 1.0
 * @Date - March 25, 2013
 * 
 * Copyright (c) 2013 EdRP, Dayalbagh Educational Institute.
 * All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or
 * without modification, are permitted provided that the following
 * conditions are met:
 *
 * Redistributions of source code must retain the above copyright
 * notice, this  list of conditions and the following disclaimer.
 *
 * Redistribution in binary form must reproducuce the above copyright
 * notice, this list of conditions and the following disclaimer in
 * the documentation and/or other materials provided with the
 * distribution.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL ETRG OR ITS CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL,SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Contributors: Members of EdRP, Dayalbagh Educational Institute
 */
package commonComponents
{
	import mx.collections.ArrayCollection;
	import mx.controls.AdvancedDataGrid;
	import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
	import mx.events.FlexEvent;
	
	import spark.components.supportClasses.ItemRenderer;
	
	
	public class CustomAdvancedDataGrid extends AdvancedDataGrid
	{	
		private var headerData : ArrayCollection;
		
		public function CustomAdvancedDataGrid()
		{
			super();
			this.addEventListener(FlexEvent.CREATION_COMPLETE,onCreationComplete);
		}	
		
		public function set gridHeaderData(headerData:ArrayCollection):void
		{
			this.headerData=new ArrayCollection;
			this.headerData=headerData;					
		}
		
		public function onCreationComplete(event:FlexEvent):void{			
			var columnArray:Array=new Array();
			for(var i:int = 0; i < headerData.length; i++){
				var dataGridColumn:AdvancedDataGridColumn=new AdvancedDataGridColumn();
				dataGridColumn.headerText=headerData.getItemAt(i)["headerText"].toString();
				dataGridColumn.dataField=headerData.getItemAt(i)["dataField"].toString();
				columnArray.push(dataGridColumn);
			}
			this.columns=columnArray;
		}
		
		public function addColumns(arr:ArrayCollection):void{
			headerData = arr;
			var columnArray:Array=new Array();
			for(var i:int = 0; i < headerData.length; i++){
				var dataGridColumn:AdvancedDataGridColumn=new AdvancedDataGridColumn();
				dataGridColumn.headerText=headerData.getItemAt(i)["headerText"].toString();
				dataGridColumn.dataField=headerData.getItemAt(i)["dataField"].toString();	
				columnArray.push(dataGridColumn);
			}
			this.columns=columnArray;
		}
	}
}